<?php

/**
 * @category    H2
 * @package     
 * @subpackage  
 * @author      Nam Nguyen
 * @copyright   
 */
class Controller {

  protected static $_current;
  protected $_noRender = false;
  protected $_params;
  public $view;

  /**
   * this class is required
   */
  protected function __construct($params = NULL) {
    $this->_params = (array) $params;
    $this->view = new View(get_class($this), @$params['action']);
  }

  public static function factory($class_name, $params = NULL) {
    self::$_current = new $class_name($params);
    return self::$_current;
  }

  public static function current() {
    return self::$_current;
  }

  /**
   * set controller has render or not
   * @param  bool  $value
   */
  public function hasRender($value = true) {
    $this->_noRender = (bool) $value;
  }

  /**
   *
   * @return string
   */
  public function render() {
    if ($this->_noRender == false) {
      $this->_noRender = true;
      return $this->view->render();
    }
  }

  /**
   *
   * @param  string  $action
   */
  public function forward($action) {
    $this->_params['action'] = $action;
    $this->_action = $action;
    $this->{$action . 'Action'} ();
  }

}